﻿'*******************************************************************************************
'* Copyright Brügmann Software GmbH, Papenburg
'* Author: Björn Kremer
'* Contact: codeplex<at>patorg.de
'* 
'* VB.CMIS is a VB.NET implementation of the Content Management Interoperability Services (CMIS) standard
'*
'* This file is part of VB.CMIS.
'* 
'* VB.CMIS is free software: you can redistribute it and/or modify
'* it under the terms of the GNU Lesser General Public License as published by
'* the Free Software Foundation, either version 3 of the License, or
'* (at your option) any later version.
'* 
'* VB.CMIS is distributed in the hope that it will be useful,
'* but WITHOUT ANY WARRANTY; without even the implied warranty of
'* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'* GNU Lesser General Public License for more details.
'* 
'* You should have received a copy of the GNU Lesser General Public License
'* along with VB.CMIS. If not, see <http://www.gnu.org/licenses/>.
'*******************************************************************************************
Imports System.Runtime.Serialization

Imports System.Xml.Serialization
Namespace TypeDefinitions
   <XmlRoot("type", Namespace:=CmisNamespaceConstants.Cmisra)>
   Public Class TypeDocumentDefinition
      Inherits TypeDefinition



      Public Property Versionable() As Boolean
      Public Property ContentStreamAllowed() As ContentStreamAllowedEnum
      Public Overrides ReadOnly Property CMISTypeName As String
         Get
            Return SharedCMISTypeName
         End Get
      End Property
      Public Shared ReadOnly Property SharedCMISTypeName As String
         Get
            Return "cmis:cmisTypeDocumentDefinitionType"
         End Get
      End Property

      Public Sub New(id As String, localName As String, displayName As String, QueryName As String, PropertyDefinitions As List(Of PropertyDefinitions.IPropertyDefinition), parentId As String)
         MyBase.new(id, localName, displayName, QueryName, PropertyDefinitions, parentId)
      End Sub
      Public Sub New()
         MyBase.New()
      End Sub


      Public Overrides Sub ReadXml(reader As Xml.XmlReader)

         Dim doc As New System.Xml.XmlDocument()
         doc.Load(reader)
         MyBase.ReadXml(doc)
         Dim node As System.Xml.XmlNode = Common.GetItemCaseInsensitiveFromXML(doc, Common.GetXMLRootName(GetType(TypeDefinition)).ToLowerInvariant)

         For Each child As System.Xml.XmlElement In node.ChildNodes
            Dim lName As String = Common.GetNodeNameWithoutPrefix(child).ToLowerInvariant
            If lName.Equals("versionable") Then
               Me.Versionable = CBool(child.InnerText)
            ElseIf lName.Equals("contentstreamallowed") Then
               Me.ContentStreamAllowed = Common.GetValueByDataMemberValue(Of ContentStreamAllowedEnum)(child.InnerText)
            End If
         Next
      End Sub

      Public Overrides Sub WriteXml(writer As System.Xml.XmlWriter)
         MyBase.WriteXml(writer)
         writer.WriteElementString("versionable", CmisNamespaceConstants.Cmis, CStr(Me.Versionable).ToLowerInvariant)
         writer.WriteElementString("contentStreamAllowed", CmisNamespaceConstants.Cmis, Common.GetDataMemberValueFromEnum(Me.ContentStreamAllowed, GetType(ContentStreamAllowedEnum)))
      End Sub


      Public Overrides ReadOnly Property BaseId As BaseIdEnum
         Get
            Return BaseIdEnum.CmisDocument
         End Get
      End Property


      Public Shared Function GetDefaultProperties(localNamespace As String, isBaseType As Boolean) As List(Of PropertyDefinitions.IPropertyDefinition)
         Dim inst As New DefaultData.DefaultProperties(localNamespace, isBaseType)
         Dim retVal As New List(Of PropertyDefinitions.IPropertyDefinition)
         retVal.Add(inst.PropertyBaseTypeId)
         retVal.Add(inst.PropertyChangeToken)
         retVal.Add(inst.PropertyCheckinComment)
         retVal.Add(inst.PropertyContentStreamFileName)
         retVal.Add(inst.PropertyContentStreamId)
         retVal.Add(inst.PropertyContentStreamLength)
         retVal.Add(inst.PropertyContentStreamMimeType)
         retVal.Add(inst.PropertyCreatedBy)
         retVal.Add(inst.PropertyCreationDate)
         retVal.Add(inst.PropertyIsImmutable)
         retVal.Add(inst.PropertyIsLatestMajorVersion)
         retVal.Add(inst.PropertyIsLatestVersion)
         retVal.Add(inst.PropertyIsMajorVersion)
         retVal.Add(inst.PropertyIsVersionSeriesCheckedOut)
         retVal.Add(inst.PropertyLastModificationDate)
         retVal.Add(inst.PropertyLastModifiedBy)
         retVal.Add(inst.PropertyName)
         retVal.Add(inst.PropertyDescription)
         retVal.Add(inst.PropertyObjectId)
         retVal.Add(inst.PropertyObjectTypeId)
         retVal.Add(inst.PropertySecondaryObjectTypeIds)
         retVal.Add(inst.PropertyVersionLabel)
         retVal.Add(inst.PropertyVersionSeriesCheckedOutBy)
         retVal.Add(inst.PropertyVersionSeriesCheckedOutId)
         retVal.Add(inst.PropertyVersionSeriesId)
         retVal.Add(inst.PropertyIsPrivateWorkingCopy)
         Return retVal
      End Function


      Public Enum ContentStreamAllowedEnum
         <EnumMember(Value:="notallowed")> _
         NotAllowed

         <EnumMember(Value:="allowed")> _
         Allowed

         <EnumMember(Value:="required")> _
         Required
      End Enum

   End Class
End Namespace